﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using Kitware.VTK;

namespace HAVTKPack
{

    public class WorldCoordinateWidget
    {
        public WorldCoordinateWidget(vtkRenderWindow renderWindow, vtkRenderWindowInteractor interactor)
        {
            this.mRenderWindow = renderWindow;
            mRenderInteractor = interactor;

        }


        vtkRenderWindow mRenderWindow;
        vtkRenderWindowInteractor mRenderInteractor;


        Boolean _isVisible = true;
        /// <summary>
        /// 是否可见
        /// </summary>
        public Boolean IsVisible
        {
            get { return _isVisible; }
            set { _isVisible = value; }
        }

        Boolean _isMoveable = true;
        /// <summary>
        /// 是否允许移动
        /// </summary>
        public Boolean IsMoveable
        {
            get { return _isMoveable; }
            set { _isMoveable = value; }
        }



        vtkAxesActor axes;
        vtkTextProperty tprop;
        vtkTextProperty tprop2;
        vtkTextProperty tprop3;
        vtkPropAssembly assembly;
        vtkOrientationMarkerWidget marker;



        public void InitialWorldCoordinateWidget()
        {

            if (mRenderWindow == null || mRenderInteractor == null)
            {
                return;
            }


            axes = vtkAxesActor.New();
            axes.SetShaftTypeToLine();
            axes.SetXAxisLabelText("X");
            axes.SetYAxisLabelText("Y");
            axes.SetZAxisLabelText("Z");
            axes.SetTotalLength(2, 2, 2);//设置坐标轴的长度
            //axes.AxisLabelsOn();
            //axes.VisibilityOff();

            tprop = vtkTextProperty.New();//设置每个坐标轴上的显示的文字属性
            tprop.ItalicOn();
            tprop.ShadowOn();
            tprop.SetFontFamilyToTimes();
            tprop.SetColor(0,0,0);

            axes.GetXAxisCaptionActor2D().SetCaptionTextProperty(tprop);
            tprop2 = vtkTextProperty.New();
            tprop2.ShallowCopy(tprop);
            axes.GetYAxisCaptionActor2D().SetCaptionTextProperty(tprop2);
            tprop3 = vtkTextProperty.New();
            tprop3.ShallowCopy(tprop);
            axes.GetZAxisCaptionActor2D().SetCaptionTextProperty(tprop3);

            assembly = vtkPropAssembly.New();
            assembly.AddPart(axes);

            marker = vtkOrientationMarkerWidget.New();
            marker.SetOutlineColor(0.9, 0.5, 0.1);
            marker.SetOrientationMarker(assembly);
            //marker.SetOrientationMarker(axes);
            marker.SetViewport(0.0, 0.0, 0.15, 0.25);//设置坐标轴的位置

            //vtkInteractorStyleTrackballCamera style = vtkInteractorStyleTrackballCamera.New();
            //iren.SetInteractorStyle(style);//设置交互方式
            //renWin.SetInteractor(iren);

            //marker.SetInteractor(renWin.GetInteractor());//用iren替代renWin->GetInteractor()也行
            //marker.SetInteractor(this.scene.VtkControl.RenderWindow.GetInteractor());

            marker.SetInteractor(mRenderWindow.GetInteractor());
            //marker.SetInteractor(mRenderInteractor);

            marker.SetEnabled(1);
            //marker.InteractiveOn();
            marker.InteractiveOff();



        }




    }


}

